<template>
	<xn-form-container :width="860" v-model:open="visible" :destroy-on-close="true" @close="onClose">
		<template #title>
			<a-space>
				<a-button @click="print" size="small">
					<template #icon><printer-outlined /></template>
					打印
				</a-button>
				<a-button @click="printExport" size="small">
					<template #icon><clear-outlined /></template>
					导出PDF
				</a-button>
			</a-space>
		</template>
		<a-spin :spinning="spinning">
			<div id="previews" style="border: 1px solid #f0f0f0" />
		</a-spin>
	</xn-form-container>
</template>

<script setup name="printPreview">
	import $ from 'jquery'
	const visible = ref(false)
	const spinning = ref(false)
	const templateGlobal = ref()
	const dataGlobal = ref()
	const emit = defineEmits(['print', 'export'])
	onMounted(() => {})
	let templatePrint = null
	// 打开
	const onOpen = (...html) => {
		visible.value = true
		spinning.value = true
		nextTick(() => {
			$('#previews').empty()
			$('#previews').html(html)
			spinning.value = false
		})
	}
	// 关闭
	const onClose = () => {
		visible.value = false
		templateGlobal.value = null
		dataGlobal.value = null
	}
	// 打印
	const print = () => {
		emit('print')
	}
	// 导出PDF
	const printExport = () => {
		emit('export')
	}
	defineExpose({
		onOpen
	})
</script>
